var app = getApp();
var util = require('../../utils/util.js');
Page({
  data: {
    guilds: '',
    register_role: '',
    //主播
    a_tmon_color: '#999',
    a_tmon_img: '("https://www.zhibohome.net/images/benyue1.png")',
    a_yday_color: '#ddba69',
    a_yday_img: '("https://www.zhibohome.net/images/zuori.png")',
    //管理员
    m_tmon_color: '#999',
    m_tmon_img: '("https://www.zhibohome.net/images/benyue1.png")',
    m_yday_color: '#ddba69',
    m_yday_img: '("https://www.zhibohome.net/images/zuori.png")',
    //会长
    //p1
    p1_tmon_color: '#999',
    p1_tmon_img: '("https://www.zhibohome.net/images/benyue1.png")',
    p1_yday_color: '#ddba69',
    p1_yday_img: '("https://www.zhibohome.net/images/zuori.png")',
    //p2
    p2_tmon_color: '#999',
    p2_tmon_img: '("https://www.zhibohome.net/images/benyue1.png")',
    p2_yday_color: '#ddba69',
    p2_yday_img: '("https://www.zhibohome.net/images/zuori.png")',

    p1_guilds: '',
    p2_guilds: '',
    tab: 0,
    p1_length: '',
    p2_length: '',
    //文字模态框
    flag: true,
    modal_text1: '',
    modal_text2: '',

    acon_height: '',
    mcon_height: '',

    time: '相较前一日',
    time1: '相较前一日',
    time2: '相较前一月',

    kong: true,
  },
  getTab() {
    wx.request({
      url: app.globalData.url + 'api/timing/applet/show',
      method: 'POST',
      success: (e) => {
        // console.log(e)
        let is_show = e.data.data.is_show,
          tel = wx.getStorageSync('reg_telephone');
        if (is_show == app.globalData.tab_is_show) {
          this.setData({
            tel: tel
          })
          this.setData({
            tabbar: {
              color: "#fff",
              selectedColor: "#d0a76c",
              backgroundColor: "#1b1b1b",
              borderStyle: "black",
              list: [{
                  pagePath: "../../pages/industry/industry",
                  text: "行业",
                  iconPath: "../../images/icon/icon_ind.png",
                  selectedIconPath: "../../images/icon/icon_indS.png",
                  selected: false
                },
                {
                  pagePath: "../../pages/mine/mine",
                  text: "我的",
                  iconPath: "../../images/icon/icon_mine.png",
                  selectedIconPath: "../../images/icon/icon_mineS.png",
                  selected: true
                }
              ],
              position: "bottom"
            },
          })
          this.editTabBar();
        } else {
          if (this.data.role == 2) {
            this.setData({
              tabbar: {
                color: "#fff",
                selectedColor: "#d0a76c",
                backgroundColor: "#1b1b1b",
                borderStyle: "black",
                list: [{
                    pagePath: "../../pages/recruit/index/index",
                    text: "招聘",
                    iconPath: "../../images/icon/icon_rec.png",
                    selectedIconPath: "../../images/icon/icon_recS.png",
                    selected: false
                  },
                  {
                    pagePath: "../../pages/earns/earns",
                    text: "赚钱",
                    iconPath: "../../images/icon/icon_money.png",
                    selectedIconPath: "../../images/icon/icon_moneyS.png",
                    selected: false
                  },
                  {
                    pagePath: "../../pages/industry/industry",
                    text: "行业",
                    iconPath: "../../images/icon/icon_ind.png",
                    selectedIconPath: "../../images/icon/icon_indS.png",
                    selected: false
                  },
                  {
                    pagePath: "../../pages/mine/mine",
                    text: "我的",
                    iconPath: "../../images/icon/icon_mine.png",
                    selectedIconPath: "../../images/icon/icon_mineS.png",
                    selected: true
                  }
                ],
                position: "bottom"
              },
            })
          } else {
            this.setData({
              tabbar: {
                color: "#fff",
                selectedColor: "#d0a76c",
                backgroundColor: "#1b1b1b",
                borderStyle: "black",
                list: [{
                    pagePath: "../../pages/recruit/index/index",
                    text: "招聘",
                    iconPath: "../../images/icon/icon_rec.png",
                    selectedIconPath: "../../images/icon/icon_recS.png",
                    selected: false
                  },
                  {
                    pagePath: "../../pages/industry/industry",
                    text: "行业",
                    iconPath: "../../images/icon/icon_ind.png",
                    selectedIconPath: "../../images/icon/icon_indS.png",
                    selected: false
                  },
                  {
                    pagePath: "../../pages/mine/mine",
                    text: "我的",
                    iconPath: "../../images/icon/icon_mine.png",
                    selectedIconPath: "../../images/icon/icon_mineS.png",
                    selected: true
                  }
                ],
                position: "bottom"
              },
            })
          }

          this.editTabBar();
        }
      },
    })
  },
  //切换tabbar的方法  
  editTabBar: function() {
    var tabbar = this.data.tabbar,
      currentPages = getCurrentPages(),
      _this = currentPages[currentPages.length - 1],
      pagePath = _this.__route__;
    (pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath);
    for (var i in tabbar.list) {
      // tabbar.list[i].selected = false;
      (tabbar.list[i].pagePath == pagePath) && (tabbar.list[i].selected = true);
    }
    _this.setData({
      tabbar: tabbar
    });
  },
  //七日收益
  earns() {
    wx.request({
      url: app.globalData.url + 'api/task/seven/day/earnings',
      data: {
        token: app.globalData.token
      },
      method: 'POST',
      success: (e) => {
        let earnsInfo = e.data.data.earnings;
        var xInfo = [],
          yInfo = [];
        earnsInfo.forEach(function(value, index) {
          var str = value.show_date;
          var str_new = str.replace(/"-"/, ".");
          var str_re = str_new.substring(5);
          value.show_date = str_re;
          value.operate_num = parseInt(value.operate_num);
          xInfo.push(value.show_date);
          yInfo.push(value.operate_num)
        })
        // outSide.xInfo = xInfo;
        // outSide.yInfo = yInfo;
        wx.setStorageSync('xInfo', xInfo)
        wx.setStorageSync('yInfo', yInfo)

        // console.log(outSide.xInfo)
        // console.log(outSide.yInfo)
      }
    })
  },
  //去福利页
  go_welfare() {
    this.earns();
    wx.navigateTo({
      url: '../mine/invite/index',
    })
  },
  //去报表
  go_report: function() {
    wx.navigateTo({
      url: '../report/report',
    })
  },
  //绑定公会
  bindGuild: function() {
    wx.navigateTo({
      url: '../bindingGuild/index/index',
    })
  },

  //文字模态框
  //出现
  modal_show: function() {
    const that = this;
    this.setData({
      flag: false
    })

  },
  //消失
  modal_hide: function() {
    this.setData({
      flag: true
    })

  },
  // 主播
  anchor_zuori_shouyi: function() {
    const that = this;
    this.setData({
      flag: false,
      modal_text1: (this.data.a_yday_color == '#ddba69') ? "您在该直播平台，昨日一天的礼物总收益" : "您在该直播平台，本月的礼物总收益",
      modal_text2: (this.data.a_yday_color == '#ddba69') ? '' : '注意：由于本月不是一个整月，所以这里的数据会根据开播情况而变化'
    })
  },
  anchor_zuori_time: function() {
    const that = this;
    this.setData({
      flag: false,
      modal_text1: (this.data.a_yday_color == '#ddba69') ? "您在该直播平台，昨日一天的开播总时长" : "您在该直播平台，本月的开播总时长",
      modal_text2: (this.data.a_yday_color == '#ddba69') ? '' : '注意：由于本月不是一个整月，所以这里的数据会根据开播情况而变化'
    })
  },


  // 管理员
  manager_zuori_shouyi: function() {
    const that = this;
    this.setData({
      flag: false,
      modal_text1: (this.data.m_yday_color == '#ddba69') ? "该管理员所管理的主播，在该直播平台，昨日一天的礼物总收益" : "该管理员所管理的主播，在该直播平台，本月的礼物总收益",
      modal_text2: (this.data.m_yday_color == '#ddba69') ? '' : '注意：由于本月不是一个整月，所以这里的数据会根据开播情况而变化'
    })
  },
  manager_zuori_count: function() {
    const that = this;
    this.setData({
      flag: false,
      modal_text1: (this.data.m_yday_color == '#ddba69') ? "该管理员所管理的主播，昨日一天的开播主播总人数" : "该管理员所管理的主播，本月的开播主播总人数",
      modal_text2: (this.data.m_yday_color == '#ddba69') ? '' : '注意：由于本月不是一个整月，所以这里的数据会根据开播情况而变化'
    })
  },

  // 会长
  p1_zuori_shouyi: function() {
    const that = this;
    this.setData({
      flag: false,
      modal_text1: (this.data.p1_yday_color == '#ddba69') ? "公会在该直播平台，昨日一天的礼物总收益" : "公会在该直播平台，本月的礼物总收益",
      modal_text2: (this.data.p1_yday_color == '#ddba69') ? "" : "注意：由于本月不是一个整月，所以这里的数据会根据开播情况而变化"
    })
  },
  p1_zuori_count: function() {
    const that = this;
    this.setData({
      flag: false,
      modal_text1: (this.data.p1_yday_color == '#ddba69') ? "公会在该直播平台，昨日一天的开播主播总人数" : "公会在该直播平台，本月的开播主播总人数",
      modal_text2: (this.data.p1_yday_color == '#ddba69') ? '' : '注意：由于本月不是一个整月，所以这里的数据会根据开播情况而变化'
    })
  },
  p2_zuori_frequency: function() {
    const that = this;
    this.setData({
      flag: false,
      modal_text1: (this.data.p2_yday_color == '#ddba69') ? "该管理员昨日一天对其管理的所有主播发起的辅导总次数。" : "该管理员本月，对其管理的所有主播发起的辅导总次数。",
      modal_text2: (this.data.p2_yday_color == '#ddba69') ? '注意：管理员对一个主播发起2次辅导，这里记为2次。' : '注意：管理员对一个主播发起2次辅导，这里记为2次。'
    })
  },
  p2_zuori_number: function() {
    const that = this;
    this.setData({
      flag: false,
      modal_text1: (this.data.p2_yday_color == '#ddba69') ? "该管理员昨日一天辅导的主播总人数。" : "该管理员本月，辅导的主播总人数。",
      modal_text2: (this.data.p2_yday_color == '#ddba69') ? '注意：管理员对一个主播发起2次辅导，这里记为1个主播。' : '注意：管理员对一个主播发起2次辅导，这里记为1个主播。'
    })
  },

  //  主播
  //昨日
  a_yday: function() {
    wx.showLoading()
    let that = this;
    this.setData({
      a_tmon_color: '#999',
      a_tmon_img: '("https://www.zhibohome.net/images/benyue1.png")',
      a_yday_color: '#ddba69',
      a_yday_img: '("https://www.zhibohome.net/images/zuori.png")',
      time: '相较前一日'
    })
    if (app.register_info.register_role == 2) {
      console.log("role_21")
      wx.request({
        url: app.globalData.url + 'api/report/index/earnings/new', //要遍历的url，http没有数据的话用https  
        method: 'POST',
        error: function(XmlHttpRequest, textStatus, errorThrown) {
          alert("操作失败!");
        },
        data: {
          token: app.globalData.token,
          type: "yesterday",
        },

        success: function(res) {
          // console.log(res.data.data)
          var guilds = res.data.data.guilds;
          let quick_guilds = res.data.data.quick_guilds;
          guilds.push(...quick_guilds);
          // console.log(guilds)
          that.setData({
            guilds: guilds
          })
          wx.hideLoading()
        },
        complete: function() {
          setTimeout(function() {
            wx.hideLoading();
          }, 5000);
        }

      })
    }
  },
  //上个月
  a_tmon: function() {
    wx.showLoading()
    let that = this;
    this.setData({
      a_tmon_color: '#ddba69',
      a_tmon_img: '("https://www.zhibohome.net/images/benyue.png")',
      a_yday_color: '#999',
      a_yday_img: '("https://www.zhibohome.net/images/zuori1.png")',
      time: '相较前一月'
    })
    if (app.register_info.register_role == 2) {
      // console.log("role_22")
      wx.request({
        url: app.globalData.url + 'api/report/index/earnings/new', //要遍历的url，http没有数据的话用https  
        method: 'POST',
        error: function(XmlHttpRequest, textStatus, errorThrown) {
          alert("操作失败!");
        },
        data: {
          token: app.globalData.token,
          type: "month"
        },
        success: function(res) {
          // console.log(res.data.data)
          var guilds = res.data.data.guilds;
          let quick_guilds = res.data.data.quick_guilds;
          guilds.push(...quick_guilds);
          // console.log(guilds)
          that.setData({
            guilds: guilds
          })
          wx.hideLoading()
        },
        complete: function() {
          setTimeout(function() {
            wx.hideLoading();
          }, 5000);
        }

      })
    }
  },



  //  管理员
  //昨日
  m_yday: function() {
    wx.showLoading()
    let that = this;
    this.setData({
      m_tmon_color: '#999',
      m_tmon_img: '("https://www.zhibohome.net/images/benyue1.png")',
      m_yday_color: '#ddba69',
      m_yday_img: '("https://www.zhibohome.net/images/zuori.png")',
      time: '相较前一日'
    });
    if (app.register_info.register_role == 3) {
      wx.request({
        url: app.globalData.url + 'api/report/index/earnings/new', //要遍历的url，http没有数据的话用https  
        method: 'POST',
        error: function(XmlHttpRequest, textStatus, errorThrown) {
          alert("操作失败!");
        },
        data: {
          token: app.globalData.token,
          type: "yesterday",
          show_type: 1
        },

        success: function(res) {
          console.log(res.data.data)
          var guilds = res.data.data.guilds;
          console.log(guilds)
          that.setData({
            guilds: guilds
          })
          wx.hideLoading()
        },
        complete: function() {
          setTimeout(function() {
            wx.hideLoading();
          }, 5000);
        }

      })
    }
  },
  //上个月
  m_tmon: function() {

    wx.showLoading();
    let that = this;
    this.setData({
      m_tmon_color: '#ddba69',
      m_tmon_img: '("https://www.zhibohome.net/images/benyue.png")',
      m_yday_color: '#999',
      m_yday_img: '("https://www.zhibohome.net/images/zuori1.png")',
      time: '相较前一月'
    });
    if (app.register_info.register_role == 3) {
      wx.request({
        url: app.globalData.url + 'api/report/index/earnings/new', //要遍历的url，http没有数据的话用https  
        method: 'POST',
        error: function(XmlHttpRequest, textStatus, errorThrown) {
          alert("操作失败!");
        },
        data: {
          token: app.globalData.token,
          type: "month",
          show_type: 0
        },
        success: function(res) {
          console.log(res.data.data)
          var guilds = res.data.data.guilds;
          console.log(guilds)
          that.setData({
            guilds: guilds
          })
          wx.hideLoading()
        },
        complete: function() {
          setTimeout(function() {
            wx.hideLoading();
          }, 5000);
        }

      })
    }
  },

  //  会长
  //前日
  p1_yday: function() {
    wx.showLoading()
    let that = this;
    this.setData({
      p1_tmon_color: '#999',
      p1_tmon_img: '("https://www.zhibohome.net/images/benyue1.png")',
      p1_yday_color: '#ddba69',
      p1_yday_img: '("https://www.zhibohome.net/images/zuori.png")',
      time1: '相较前一日'
    });
    if (app.register_info.register_role == 1) {
      wx.request({
        url: app.globalData.url + 'api/report/index/earnings/new', //要遍历的url，http没有数据的话用https  
        method: 'POST',
        error: function(XmlHttpRequest, textStatus, errorThrown) {
          alert("操作失败!");
        },
        data: {
          token: app.globalData.token,
          type: "yesterday",
          show_type: 0
        },

        success: function(res) {
          // console.log(res.data.data)
          var p1_guilds = res.data.data.guilds;
          let quick_guilds = res.data.data.quick_guilds;
          p1_guilds.push(...quick_guilds);
          // console.log(p1_guilds)
          that.setData({
            p1_guilds: p1_guilds
          })
          wx.hideLoading()
        },
        complete: function() {
          setTimeout(function() {
            wx.hideLoading();
          }, 5000);
        }

      })
    }
  },
  //上个月
  p1_tmon: function() {

    wx.showLoading();
    let that = this;
    this.setData({
      p1_tmon_color: '#ddba69',
      p1_tmon_img: '("https://www.zhibohome.net/images/benyue.png")',
      p1_yday_color: '#999',
      p1_yday_img: '("https://www.zhibohome.net/images/zuori1.png")',
      time1: '相较前一月'
    });
    if (app.register_info.register_role == 1) {
      wx.request({
        url: app.globalData.url + 'api/report/index/earnings/new', //要遍历的url，http没有数据的话用https  
        method: 'POST',
        error: function(XmlHttpRequest, textStatus, errorThrown) {
          alert("操作失败!");
        },
        data: {
          token: app.globalData.token,
          type: "month",
          show_type: 0
        },
        success: function(res) {
          // console.log(res.data.data)
          var p1_guilds = res.data.data.guilds;
          let quick_guilds = res.data.data.quick_guilds;
          p1_guilds.push(...quick_guilds);
          // console.log(p1_guilds)
          that.setData({
            p1_guilds: p1_guilds
          })
          wx.hideLoading()
        },
        complete: function() {
          setTimeout(function() {
            wx.hideLoading();
          }, 5000);
        }

      })
    }

  },
  //p2

  p2_yday: function() {
    wx.showLoading()
    let that = this;
    this.setData({
      p2_tmon_color: '#999',
      p2_tmon_img: '("https://www.zhibohome.net/images/benyue1.png")',
      p2_yday_color: '#ddba69',
      p2_yday_img: '("https://www.zhibohome.net/images/zuori.png")',
      time2: '相较前一日'
    });
    if (app.register_info.register_role == 1) {
      wx.request({
        url: app.globalData.url + 'api/report/index/earnings/new', //要遍历的url，http没有数据的话用https  
        method: 'POST',
        error: function(XmlHttpRequest, textStatus, errorThrown) {
          alert("操作失败!");
        },
        data: {
          token: app.globalData.token,
          type: 'yesterday',
          show_type: 1

        },
        success: function(res) {
          //  console.log(res.data.data.admins)
          // var p2_guilds = res.data.data.admins;
          // var length = p2_guilds.length;
          var p2_guilds = res.data.data.admins;
          // let quick_guilds = res.data.data.quick_guilds;
          // p2_guilds.push(...quick_guilds);
          //  console.log(p2_guilds.length)
          that.setData({
            p2_guilds: p2_guilds,
            // p2_length: length
          })
          wx.hideLoading();
        },
        complete: function() {
          setTimeout(function() {
            wx.hideLoading();
          }, 5000);
        }

      })

    }
  },
  p2_tmon: function() {
    wx.showLoading()
    let that = this;
    this.setData({
      p2_tmon_color: '#ddba69',
      p2_tmon_img: '("https://www.zhibohome.net/images/benyue.png")',
      p2_yday_color: '#999',
      p2_yday_img: '("https://www.zhibohome.net/images/zuori1.png")',
      time2: '相较前一月'
    });
    if (app.register_info.register_role == 1) {
      wx.request({
        url: app.globalData.url + 'api/report/index/earnings/new', //要遍历的url，http没有数据的话用https  
        method: 'POST',
        error: function(XmlHttpRequest, textStatus, errorThrown) {
          alert("操作失败!");
        },
        data: {
          token: app.globalData.token,
          type: 'month',
          show_type: 1

        },
        success: function(res) {
          //  console.log(res.data.data.admins)
          // var p2_guilds = res.data.data.admins;
          // var length = p2_guilds.length;
          var p2_guilds = res.data.data.admins;
          // let quick_guilds = res.data.data.quick_guilds;
          // p2_guilds.push(...quick_guilds);
          //  console.log(p2_guilds.length)
          that.setData({
            p2_guilds: p2_guilds,
            // p2_length: length
          })
          wx.hideLoading();
        },
        complete: function() {
          setTimeout(function() {
            wx.hideLoading();
          }, 5000);
        }

      })

    }
  },
  //埋点
  secret() {
    wx.request({
      url: app.globalData.url + 'api/timing/common/oncilck/bottom',
      data: {
        token: app.globalData.token,
        from: 'WxMiNi',
        type: '3'
      },
      method: 'POST',
      success: (e) => {
        console.log(e)
      }
    })
  },

  onLoad: function() {
    wx.showLoading();
    this.getTab();
    var that = this;
    if (app.register_info.register_role == 3) {
      //管理员遍历
      wx.request({
        url: app.globalData.url + 'api/report/index/earnings/new', //要遍历的url，http没有数据的话用https  
        method: 'POST',
        error: function(XmlHttpRequest, textStatus, errorThrown) {
          alert("操作失败!");
        },
        data: {
          token: app.globalData.token
        },
        success: function(res) {
          var guilds = res.data.data.guilds;
          // console.log(guilds)
          that.setData({
            guilds: guilds
          })
          wx.hideLoading();
        }

      })
    } else {

    }
    if (app.register_info.register_role == 2) {
      //主播遍历
      wx.request({
        url: app.globalData.url + 'api/report/index/earnings/new', //要遍历的url，http没有数据的话用https  
        method: 'POST',
        error: function(XmlHttpRequest, textStatus, errorThrown) {
          alert("操作失败!");
        },
        data: {
          token: app.globalData.token,

        },
        success: function(res) {
          // console.log(res)
          var guilds = res.data.data.guilds;
          let quick_guilds = res.data.data.quick_guilds;
          guilds.push(...quick_guilds);
          // console.log(guilds)
          that.setData({
            guilds: guilds
          })
          wx.hideLoading();
        }

      })
    } else {

    }
    if (app.register_info.register_role == 1) {
      //会长遍历

      //团队收益
      wx.request({
          url: app.globalData.url + 'api/report/index/earnings/new', //要遍历的url，http没有数据的话用https  
          method: 'POST',
          error: function(XmlHttpRequest, textStatus, errorThrown) {
            alert("操作失败!");
          },
          data: {
            token: app.globalData.token,
            type: 'yesterday',
            show_type: 0

          },
          success: function(res) {
            // console.log(res)
            var p1_guilds = res.data.data.guilds;
            let quick_guilds = res.data.data.quick_guilds;
            p1_guilds.push(...quick_guilds);
            // console.log(p1_guilds.length)
            that.setData({
              p1_guilds: p1_guilds,
            })
            wx.hideLoading();
          }

        }),
        //团队管理
        wx.request({
          url: app.globalData.url + 'api/report/index/earnings/new', //要遍历的url，http没有数据的话用https  
          method: 'POST',
          error: function(XmlHttpRequest, textStatus, errorThrown) {
            alert("操作失败!");
          },
          data: {
            token: app.globalData.token,
            type: 'yesterday',
            show_type: "1"

          },
          success: function(res) {
            console.log(res)
            // console.log(res.data.data.admins)
            var p2_guilds = res.data.data.admins;
            // console.log(p2_guilds.length)
            that.setData({
              p2_guilds: p2_guilds,
            })
            wx.hideLoading();
          }

        })
    } else {

    }

    // if (this.data.guilds == "") {
    //   this.setData({
    //     kong: false,
    //   })
    // } 
    // if (this.data.p1_guilds == "") {
    //   this.setData({
    //     kong: false,
    //   })
    // }
  },
  onReady: function() {


  },
  onShow: function() {
    var that = this;
    //读取全局储存的角色
    that.setData({
      register_role: app.register_info.register_role,
    })
    //授权检测
    if (!(wx.getStorageSync('reg_register_role'))) {
      wx.redirectTo({
        url: '../author/author',
      })
      // console.log('跳转')
    } else {
      this.earns();
      this.secret();
    }
    //动态获取节点元素的高度
    //     if (app.register_info.register_role == 1) {
    //       setTimeout(function() {
    //         //创建节点选择器
    //         var query = wx.createSelectorQuery();
    //         //选择id
    //         query.select('.a_con').boundingClientRect()
    //         query.exec(function(res) {
    //           //res就是 所有标签为mjltest的元素的信息 的数组
    //           // console.log(res);
    //           //取高度
    //           // console.log(res[0].height);
    //           that.setData({
    //             acon_height: res[0].height + res[0].top
    //           })
    //         })
    //       }, 2000)
    //       setTimeout(function() {
    //         //创建节点选择器
    //         var query = wx.createSelectorQuery();
    //         //选择id
    //         query.select('.m_con').boundingClientRect()
    //         query.exec(function(res) {
    //           //res就是 所有标签为mjltest的元素的信息 的数组
    //           // console.log(res);
    //           //取高度
    //           // console.log(res[0].height);
    //           that.setData({
    //             mcon_height: res[0].height + res[0].top
    //           })
    //         })
    //       }, 2000)
    //       wx.hideLoading();

    //     }


    wx.showLoading();
    var that = this;
    //读取全局储存的角色
    that.setData({
      register_role: app.register_info.register_role,
    })


    if (app.register_info.register_role == 3) {
      //管理员遍历
      wx.request({
        url: app.globalData.url + 'api/report/index/earnings/new', //要遍历的url，http没有数据的话用https  
        method: 'POST',
        error: function(XmlHttpRequest, textStatus, errorThrown) {
          alert("操作失败!");
        },
        data: {
          token: app.globalData.token
        },
        success: function(res) {
          var guilds = res.data.data.guilds;
          // console.log(guilds)
          that.setData({
            guilds: guilds
          })
          wx.hideLoading();
        }

      })
    } else {

    }
    if (app.register_info.register_role == 2) {
      //主播遍历
      wx.request({
        url: app.globalData.url + 'api/report/index/earnings/new', //要遍历的url，http没有数据的话用https  
        method: 'POST',
        error: function(XmlHttpRequest, textStatus, errorThrown) {
          alert("操作失败!");
        },
        data: {
          token: app.globalData.token,

        },
        success: function(res) {
          // console.log(res)
          var guilds = res.data.data.guilds;
          let quick_guilds = res.data.data.quick_guilds;
          guilds.push(...quick_guilds);
          // console.log(guilds)
          that.setData({
            guilds: guilds
          })
          wx.hideLoading();
        }

      })
    } else {

    }
    if (app.register_info.register_role == 1) {
      //会长遍历

      //团队收益
      wx.request({
          url: app.globalData.url + 'api/report/index/earnings/new', //要遍历的url，http没有数据的话用https  
          method: 'POST',
          error: function(XmlHttpRequest, textStatus, errorThrown) {
            alert("操作失败!");
          },
          data: {
            token: app.globalData.token,
            type: 'yesterday',
            show_type: 0

          },
          success: function(res) {
            console.log(res)
            var p1_guilds = res.data.data.guilds;
            let quick_guilds = res.data.data.quick_guilds;
            p1_guilds.push(...quick_guilds);
            // console.log(p1_guilds.length)
            that.setData({
              p1_guilds: p1_guilds,
            })
            wx.hideLoading();
          }

        }),
        //团队管理
        wx.request({
          url: app.globalData.url + 'api/report/index/earnings/new', //要遍历的url，http没有数据的话用https  
          method: 'POST',
          error: function(XmlHttpRequest, textStatus, errorThrown) {
            alert("操作失败!");
          },
          data: {
            token: app.globalData.token,
            type: 'yesterday',
            show_type: "1"

          },
          success: function(res) {
            console.log(res)
            // console.log(res.data.data.admins)
            var p2_guilds = res.data.data.admins;
            // console.log(p2_guilds.length)
            that.setData({
              p2_guilds: p2_guilds,
            })
            wx.hideLoading();
          }

        })
    } else {

    }
    wx.hideLoading()
  },
  // 会长
  tab_slide: function(e) { //滑动切换tab 
    var that = this;
    that.setData({
      tab: e.detail.current
    });
  },
  tab_click: function(e) { //点击tab切换
    var that = this;
    if (that.data.tab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        tab: e.target.dataset.current
      })
    }
  }

})